#ifndef SERVER_H
#define SERVER_H

#pragma comment( linker, "/defaultlib:ws2_32.lib" )

#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#include <winsock.h>
#include <iostream>
#include <windows.h>
#include <time.h>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iterator>
#include <sys/stat.h>

using namespace std;

#define SERVER_PORT 5001
#define DATA_SIZE 256
#define TRACE 1
#define WINDOW_SIZE 10

typedef struct myPacket
{
	int sequenceNumber;				//sequence number
	bool terminate;					//terminate flag, true: terminate, false: not terminate
	bool acknowledgement;			//true:ACK, false:NAK  
	char data[DATA_SIZE];			//data
	int dataSize;                   //size of data
	bool duplicate;                  //dublicate name flag, true:file with same name exists, false; not exists
	myPacket()
	{
		terminate = false;
		acknowledgement = false;
		duplicate=false;
	}
};

class server
{
public:
	server(char *fn = "log.txt");
	~server();
	void run();
private:
	sockaddr_in myaddr;
	sockaddr_in remaddr;
	int addrSize;
	int fd;
	ofstream fout;		//log file
	bool fileExist(const string &);
	int getFileSize(const string &);
	bool isBinaryFile(const string &);
	int getTextFileCount(const string &);
	int getNextSequenceNumber(int);
	vector<string> listDirectoryContents(const char *);
	int stringToInt(string);
};

#endif